package com.android.hello;

import android.content.Context; 
import android.view.MotionEvent; 
import android.view.GestureDetector.SimpleOnGestureListener; 
import android.widget.Toast; 
 
public class MyGestureListener extends SimpleOnGestureListener { 

    private Context mContext; 
    private static final int SWIPE_MIN_DISTANCE = 120;
    private static final int SWIPE_MAX_OFF_PATH = 250;
    private static final int SWIPE_THRESHOLD_VELOCITY = 100;

    MyGestureListener(Context context) { 

        mContext = context; 

    } 

    @Override 

    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, 

            float velocityY) { 
    	
    		if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY && Math.abs(e1.getY() - e2.getY())<SWIPE_MAX_OFF_PATH) {
    			Toast.makeText(mContext, "FLINGLEFT " + e2.getAction(), Toast.LENGTH_SHORT).show(); 
    		
    		} 
    		else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY && Math.abs(e1.getY() - e2.getY())<SWIPE_MAX_OFF_PATH) {
    			Toast.makeText(mContext, "FLINGRIGHT " + e2.getAction(), Toast.LENGTH_SHORT).show(); 
    		}

    		if(e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY && Math.abs(e1.getX() - e2.getX())<SWIPE_MAX_OFF_PATH) {
    			Toast.makeText(mContext, "FLINGUP " + e2.getAction(), Toast.LENGTH_SHORT).show(); 
    		} 
    		else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE &&Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY && Math.abs(e1.getX() - e2.getX())<SWIPE_MAX_OFF_PATH) {
    			Toast.makeText(mContext, "FLINGDOWN " + e2.getAction(), Toast.LENGTH_SHORT).show(); 
    		}
       

        return false; 

    } 

 

   

} 

